﻿namespace ImageProcessing
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;

    /// <summary>
    /// Histogram Class
    /// </summary>
    public class Histogram
    {
        /// <summary>
        /// Bits count in Red colors
        /// </summary>
        private double[] red = new double[256];

        /// <summary>
        /// Bits count in Green colors
        /// </summary>
        private double[] green = new double[256];

        /// <summary>
        /// Bits count in Blue colors
        /// </summary>
        private double[] blue = new double[256];

        /// <summary>
        /// Bits count in Gray colors
        /// </summary>
        private double[] gray = new double[256];

        /// <summary>
        /// Gets or sets the gray array.
        /// </summary>
        /// <value>
        /// The gray1.
        /// </value>
        public double[] Gray1
        {
            get { return this.gray; }
            set { this.gray = value; }
        }

        /// <summary>
        /// Gets or sets the blue array.
        /// </summary>
        /// <value>
        /// The blue1.
        /// </value>
        public double[] Blue1
        {
            get { return this.blue; }
            set { this.blue = value; }
        }

        /// <summary>
        /// Gets or sets the green array.
        /// </summary>
        /// <value>
        /// The green1.
        /// </value>
        public double[] Green1
        {
            get { return this.green; }
            set { this.green = value; }
        }

        /// <summary>
        /// Gets or sets the red array.
        /// </summary>
        /// <value>
        /// The red1.
        /// </value>
        public double[] Red1
        {
            get { return this.red; }
            set { this.red = value; }
        }

        /// <summary>
        /// Fills the red array.
        /// </summary>
        /// <param name="image">The image.</param>
        public void FillRedArray(DImage image)
        {
            for (int i = 0; i < image.Height; i++)
            {
                for (int j = 0; j < image.Width; j++)
                {
                    this.red[image.ImageStructArray[i, j].R]++;
                }
            }
        }

        /// <summary>
        /// Fills the green array.
        /// </summary>
        /// <param name="image">The image.</param>
        public void FillGreenArray(DImage image)
        {
            for (int i = 0; i < image.Height; i++)
            {
                for (int j = 0; j < image.Width; j++)
                {
                    this.green[image.ImageStructArray[i, j].G]++;
                }
            }
        }

        /// <summary>
        /// Fills the blue array.
        /// </summary>
        /// <param name="image">The image.</param>
        public void FillBlueArray(DImage image)
        {
            for (int i = 0; i < image.Height; i++)
            {
                for (int j = 0; j < image.Width; j++)
                {
                    this.blue[image.ImageStructArray[i, j].B]++;
                }
            }
        }

        /// <summary>
        /// Fillalls the array.
        /// </summary>
        /// <param name="image">The image.</param>
        public void FillallArray(DImage image)
        {
            for (int i = 0; i < image.Height; i++)
            {
                for (int j = 0; j < image.Width; j++)
                {
                    this.red[image.ImageStructArray[i, j].R]++;
                    this.green[image.ImageStructArray[i, j].G]++;
                    this.blue[image.ImageStructArray[i, j].B]++;
                }
            }
        }

        /// <summary>
        /// Fills the gray array.
        /// </summary>
        /// <param name="image">The image.</param>
        public void FillGrayArray(DImage image)
        {
            int x;
            for (int i = 0; i < image.Height; i++)
            {
                for (int j = 0; j < image.Width; j++)
                {
                    x = (image.ImageStructArray[i, j].R + image.ImageStructArray[i, j].G + image.ImageStructArray[i, j].B) / 3;
                    this.gray[x]++;
                }
            }
        }

        /// <summary>
        /// Updates the histogram.
        /// </summary>
        /// <param name="image">The image.</param>
        public void UpdateHistogram(DImage image)
        {
            this.FillRedArray(image);
            this.FillGreenArray(image);
            this.FillBlueArray(image);
            this.FillGrayArray(image);
        }
    }
}
